package org.freespace.controller;


import lombok.extern.slf4j.Slf4j;
import org.freespace.service.IJmxThreadgroupService;
import org.freespace.utils.response.CommonResult;
import org.freespace.vo.JmeterConcurrencyThreadVO;
import org.freespace.vo.JmeterThreadVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 线程组 前端控制器
 * </p>
 *
 * @author liuqi
 * @since 2023-05-08
 */
@Slf4j
@RestController
@RequestMapping("/threadgroup")
public class JmxThreadGroupController {

    @Autowired
    IJmxThreadgroupService service;

    @GetMapping(value = "/list/{jmxId}")
    public CommonResult list(@PathVariable("jmxId") Integer jmxId) {
        return CommonResult.success(service.list(jmxId));
    }
    @GetMapping(value = "/{threadGroupId}")
    public CommonResult get(@PathVariable("threadGroupId") Integer threadGroupId) {
        return CommonResult.success(service.getById(threadGroupId));
    }

    @GetMapping(value = "/samplelist/{jmxId}/{threadGroupId}")
    public CommonResult samplelist(@PathVariable("jmxId") Integer jmxId, @PathVariable("threadGroupId") Integer threadGroupId) {
        return CommonResult.success(service.samplelist(jmxId, threadGroupId));
    }

    @GetMapping(value = "/enable/{threadGroupId}/{isEnable}")
    public CommonResult enable(@PathVariable("threadGroupId") Integer threadGroupId, @PathVariable("isEnable") Integer isEnable) throws Exception {
        service.enableThreadGroup(threadGroupId, isEnable);
        return CommonResult.success();
    }

    @PostMapping("settings")
    public CommonResult settings(@RequestBody JmeterThreadVO req) throws Exception {
        service.updateJmxThread(req);
        return CommonResult.success();
    }

    @PostMapping("concurrencySettings")
    public CommonResult concurrencySetting(@RequestBody JmeterConcurrencyThreadVO req) throws Exception {
        service.updateJmxConcurrencyThread(req);
        return CommonResult.success();
    }

    @PostMapping("arrivalsSettings")
    public CommonResult arrivalsSettings(@RequestBody JmeterConcurrencyThreadVO req) throws Exception {
        service.updateJmxArrivalsThread(req);
        return CommonResult.success();
    }
}
